package DBHelper;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBHelper {
    private static final String host = "jdbc:mysql://localhost:3306/project";
    private static final String login = "root";
    private static final String pass = "";
    private static Connection getConnection() throws SQLException {
        Connection con;
        try {
            con = DriverManager.getConnection (
                host, 
                login, 
                pass
            );
            if (con!=null) { return con; }
        }
        catch(SQLException e) { throw e; }
        return null;
    }
    public static ResultSet executeQuery(String query) throws SQLException {
        java.sql.Statement stmt;
        Connection con = getConnection();
        stmt = con.createStatement();
        //stmt.close(); почему-то не пашет с этой строкой
        return stmt.executeQuery(query);
    }
    
    public static void updateQuery(String query) throws SQLException {
        java.sql.Statement stmt;
        Connection con = getConnection();
        stmt = con.createStatement();
        stmt.execute(query);
        stmt.close();
        con.close();
    }
}
